import 'package:sow_app_core/src/error/exception.dart';
import 'package:test/test.dart';

import 'package:sow_app_mock/sow_app_mock.dart';

void main() {
  group('register controller test group', () {
    final MockRegisterPresenter presenter = MockRegisterPresenter();
    presenter.username = "foo";
    presenter.password = "bar";
    presenter.captchaCode = "666";
    final controller = MockRegisterController(presenter, MockRestClient());
    test("should present valid token when invoke register", () async {
      await controller.register();
      await Future.doWhile(() => presenter.flag = false);
      expect(controller.client.authorization, isNotEmpty);
    });
    test("should present valid captcha list data when invoke getCaptcha",
        () async {
      controller.getCaptcha();
      await Future.doWhile(() => presenter.flag = false);
      expect(presenter.captcha.length, greaterThan(500));
    });
    test("should present ServerException when invoke register with exist user",
        () async {
      try {
        presenter.username = "17612345678";
        await controller.register();
        await Future.doWhile(() => presenter.flag = false);
      } on Exception catch (e) {
        expect(e, isA<ServerException>());
      }
    });
  });
}
